package threadException;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class ThreadException3 {
    /**
     * futureTask.get()，获取返回值时，子线程报错会影响主方法
     * 也就是说没有返回值就不影响，有返回值就影响
     * @param args
     * @throws InterruptedException
     * @throws ExecutionException
     */
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        System.out.println("主线程开始");
        FutureTask<String> futureTask = new FutureTask<>(() -> {
            System.out.println("子线程2开始");
            TimeUnit.SECONDS.sleep(2);
            int i = 1 / 0;
            System.out.println("子线程2结束");
            return "子线程二";
        });
        Thread thread = new Thread(futureTask);
        thread.start();
//        String s = futureTask.get();
//        System.out.println(s);
//        TimeUnit.SECONDS.sleep(2);
//        System.out.println("主线程截至");
    }
}
